package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IHomeService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.user.annotation.Anoymous;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author AhaNg
 * @Date 2022/1/20 16:59
 * @description:
 * @return:
 */
@RestController
@RequestMapping("shopping")
@Slf4j
@Anoymous
public class PrincipalSheetController {

    @Reference(timeout=3000,check=false)
    IHomeService homeService;

    @GetMapping("homepage")
    public ResponseData getPrincipal(){

        HomePageResponse homePageResponse=homeService.homepage();
        if (ShoppingRetCode.SUCCESS.getCode().equals(homePageResponse.getCode())){

            //返回一个包含主页商品信息的对象
            return new ResponseUtil().setData(homePageResponse.getPanelContentItemDtos());
        }
        //返回一个错误信息对象
        return new ResponseUtil().setErrorMsg(homePageResponse.getMsg());
    }
    
}
